﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LLBanner.aspx.cs" Inherits="HelloLLLLL.Blog.Admin.page.LLBanner" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Banner管理</title>
     <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all"/>   
    <link rel="stylesheet" href="../css/public.css" media="all"/>
    <script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <style>
        .llfile {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
}
.llfile input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
}
.llfile:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
}
    </style>
    <script>
        layui.use(['jquery'], function () {
            var $ = layui.$;
            $(".llfile").on("change", "input[type='file']", function () {

                var filePath = $(this).val();
                if (filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1 || filePath.indexOf("gif") != -1) {
                    $(".fileerrorTip").html("").hide();
                    var arr = filePath.split('\\');
                    var fileName = arr[arr.length - 1];
                    $(".showFileName").html(filePath);
                } else {
                    $(".showFileName").html("");
                    $(".fileerrorTip").html("您未上传文件，或者您上传文件类型有误！").show();
                    return false
                }
            })
            $("#upLLImg").click(function () {
                var formData = new FormData();
                var upFile = $('#imgFile1')[0].files[0];;
                formData.append("userfile", upFile);

                $.ajax({
                    url: '/admin/AdminPostData.ashx?action=uploadImg1&dir=banner&width=800',
                    dataType: 'json',
                    type: 'POST',
                    data: formData,
                    processData: false, // 使数据不做处理
                    contentType: false, // 不要设置Content-Type请求头
                    success: function (data) {
                        if (data.error == 0) {
                            console.log(data.url);

                            $("#homeImg").val(data.url);
                            $("#showLLImg").attr("src", data.url);
                        }
                        else {
                            $(".fileerrorTip").html(data.message);
                        }
                    },
                    error: function (response) {
                        console.log(response);
                    }
                });
            })
        });

    </script>
</head>
<body>
    <div class="layuimini-container">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item" style="width: 350px;">
                <div class="layui-input-block">

                  <a href="javascript:;" class="llfile">选择文件
                    <input type="file" name="imgFile" id="imgFile1"/>
                  </a>
                    <a href="javascript:;" class="llfile" id="upLLImg">上传</a>
                    <div class="fileerrorTip"></div>
                    <label class="layui-form-label">文件名：</label>
                    <div class="showFileName"></div>
                    <div>
                        <img src="" id="showLLImg"/>
                    </div>
                </div>
            </div>
       
      <div class="layui-form-item" style="width: 650px;">
                <label class="layui-form-label required">图片标题</label>
                <div class="layui-input-block">                    
                    <input type="text" id="banTitle" name="BanTitle"   value="" class="layui-input" />
                </div>
            </div>
           <div class="layui-form-item" style="width: 650px;">
                <label class="layui-form-label required">跳转地址</label>
                <div class="layui-input-block">
                    <input type="hidden" id="banId" value="" name="BanId" />
                    <input type="text" id="banAddr" name="BanAddr" lay-verify="required" lay-reqtext="跳转地址不能为空" placeholder="请输入跳转地址" value="" class="layui-input" />
                </div>
            </div>
        <div class="layui-form-item" style="width: 650px;">
                <label class="layui-form-label required">图片地址</label>
                <div class="layui-input-block">                    
                    <input type="text" id="homeImg" name="BanImgAddr"  readonly="readonly" value="" class="layui-input" />
                </div>
            </div>
        <div class="layui-form-item" style="width: 650px;">
                <label class="layui-form-label required">图片排序</label>
                <div class="layui-input-block">
                    <input type="text" id="banSort" name="BanSort"  value="1" class="layui-input" />
                </div>
            </div>
       <div class="layui-form-item" >
                <label class="layui-form-label">是否展示</label>
                <div class="layui-input-block">
                    <select name="BanIsShow" id="banIsShow">
                        <option value="1">显示</option>
                        <option value="0" >不显示</option>                        
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
    </div>
</div>
    <script>


        layui.use(['form', 'layer','jquery'], function () {
            var form = layui.form,
                layer = layui.layer,               
                $ = layui.jquery;

            //监听提交
            form.on('submit(saveBtn)', function (data) {

                $.ajax(
                    {
                        url: "/Admin/AdminPostData.ashx?action=bannerAE",
                        type: "post",
                        data: data.field,
                        dataType: "JSON",
                        success: function (dd) {
                            console.log(dd.IsOk);

                            if (dd.IsOk == "Ok") {
                                layer.alert(dd.msg, { title: '操作提示' }, function () {

                                    
                                        layer.close(0);

                                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(iframeIndex);
                                  
                                });
                            }
                            else {
                                layer.msg(dd.msg);
                            }
                        }
                    }
                )
                return false;
            });

        });
    </script>
</body>
</html>
